package com.zcl.demo.concurrent;

import java.util.concurrent.CountDownLatch;

/**
 * @author 周成龙
 * @date 2021-01-27 12:43
 * description
 */
public class CountDownLatchDemo {
    private static CountDownLatch latch=new CountDownLatch(2);

    public static void main(String[] args) {

        new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName()+"    i="+i);
                }
                latch.countDown();
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println(Thread.currentThread().getName()+"    j="+i);
                }
                latch.countDown();
            }
        }.start();


        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName()+"    k="+i);
        }
    }
}
